package com.zwz.crawler.mangeInfo;

import com.zwz.constant.Constant;
import com.zwz.parse.JsonParserUtil;
import com.zwz.resp.LicenseInfo;
import com.zwz.vo.LicVo;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;

import static com.zwz.constant.Constant.ENTERPRISE_ID;

@Slf4j
public class TungeeLicenseQuery {
    //private static final String ENTERPRISE_ID = "577de19eadf21dc4";

    public static List<LicVo> LicenseInfo(  String ENTERPRISE_ID ) {
        try {
            // 构建严格编码的URL
            String encodedId = URLEncoder.encode(ENTERPRISE_ID, String.valueOf(StandardCharsets.UTF_8));
            String url = "https://sales.tungee.com/api/enterprise/info/license-list?enterprise_id=" + encodedId;

            // 发送严格配置的请求
            Connection.Response response = Jsoup.connect(url)
                    .method(Connection.Method.GET)
                    .header("authority", "sales.tungee.com")
                    .header("accept", "*/*")
                    .header("accept-encoding", "gzip, deflate, br, zstd")
                    .header("accept-language", "zh-CN,zh;q=0.9")
                    .header("cache-control", "no-cache")
                    .header("cookie", Constant.cookies)
                    .header("pragma", "no-cache")
                    .header("priority", "u=1, i")
                    .header("referer", "https://sales.tungee.com/enterprise-details/"+encodedId+"/enterprise-information/bussinesss-information")
                    .header("sec-ch-ua", "\"Not;A=Brand\";v=\"24\", \"Chromium\";v=\"128\"")
                    .header("sec-ch-ua-mobile", "?0")
                    .header("sec-ch-ua-platform", "\"Windows\"")
                    .header("sec-fetch-dest", "empty")
                    .header("sec-fetch-mode", "cors")
                    .header("sec-fetch-site", "same-origin")
                    .header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36")
                    .header("x-tonxis-pid", "67864ea75f69e05d3b544ca7")
                    .ignoreContentType(true)
                    .ignoreHttpErrors(true)
                    .timeout(30000)
                    .execute();

            // 输出原始响应
           log.info("HTTP状态码: " + response.statusCode());
           log.info("响应内容:\n" + response.body());

            //解析为对应的
            List<LicVo> bean = JsonParserUtil.ParseLic(response.body());

            return bean;

        } catch (IOException e) {
            System.err.println("请求失败: " + e.getMessage());

        }

        return  null;
    }

//    private static String getCookies() {
//        return "_tx_pid=67864ea75f69e05d3b544ca7; "
//                + "__wpkreporterwid_=cc4a07fc-7bb9-40a4-96bc-2cbac34b658f; "
//                + "__last_enter_version=sales; "
//                + "_co_i=6805a5576eceb9637696f09d; "
//                + "_tx_uid=680701dddca941522b77e864; "
//                + "_tx_cid=6805a5576eceb9637696f09d; "
//                + "DISTINCT_ID=b84fe276-099f-4932-92b3-d54b92ae384b; "
//                + "_tx_sid=MTc0NTMwMTE0MzYyMjo4MmQ2OTQ5MTY0NjU2ODNmYjQ5MjlmMjc3NDg5ZDFlZg==; "
//                + "SecurityCenterDuId=ImFBSG15RzdPdVdPdCtsWnNGMFVuSXhVPSI.GuzDmQ.Pxm3uG40J8gTQGNwc2K6fX_MFS0; "
//                + "remember_token=680b3219dca94151d0217627|34818d350c18319a1eeb92d5dbe213bb4b12acaa3b376797d72ad39e95e124fb0e49b10789a251113f9e7472d910d453bc4132777b1795cb3511954bea5f068a; "
//                + "Hm_lvt_f2ee75449fc055cc4dbceb4fe403bea3=1745562921,1745564178,1745719089,1745736192; "
//                + "HMACCOUNT=B4E402DF057C895E; "
//                + "tg_referrer_source=direct; "
//                + "acw_tc=1a0c380a17458112439375032e005feef6fc76b5a8698d016694855911074d; "
//                + "Hm_lpvt_f2ee75449fc055cc4dbceb4fe403bea3=1745811293; "
//                + "accountCenterSessionId=.eJwtjUELgjAYQP_Ld_awrdL0FhVB5ESQRl7GdJ-p2AK3koz-eyM6PniP9waDqKVVT5TuLnUFSaMGiwHUrTIGB0hgwgoCeFgcZac9h2tSLRiNda3iJV1RTRiNQhZ5yf4E3p-HUuRTJvYuO6Q02xJyma_kJI4d320cZ_mcFvmLC96Xhb75UDYj2vY__3wBEr0vhA.GvCI3Q.GWNe_DfydTvyLDu14bUiFvejzLI; "
//                + "doncusSessionId=eyJfZnJlc2giOmZhbHNlLCJ1c2VyX2lkIjoiNjgwNzAxZGRkY2E5NDE1MjJiNzdlODY0In0.GvCI9g.AzaNJLHdp7Bn75I7pZ7qI36JqWc";
//    }
}